﻿using DevExpress.XtraRichEdit;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraBars;
using DevExpress.XtraRichEdit.API.Native;
namespace AHCS
{
   public static class ExtionComm
    {
        public static void AppendBackColorfulDev(this RichEditControl re, string keytext, Color color)
        {
            DocumentRange[] list = re.Document.FindAll(new System.Text.RegularExpressions.Regex(keytext));

            for (int i = 0; i < list.Length; i++)
            {
                CharacterProperties cp = re.Document.BeginUpdateCharacters(list[i]);

             //   cp.ForeColor = Color.Red;
                cp.BackColor = color;
                re.Document.EndUpdateCharacters(cp); 
            }
        }

        public static void AppendBackColorful(this RichTextBox curentRch, string keytext, Color color)
        {
            if (!string.IsNullOrWhiteSpace(curentRch.Text) && !string.IsNullOrWhiteSpace(keytext))
            {
                int isfind = 0;
                isfind = curentRch.Text.IndexOf(keytext, 0);
                
                if (isfind == -1)
                {
                    return;
                }
                else
                {
                    while (isfind>=0)
                    {
                        curentRch.SelectionStart = isfind;
                        curentRch.SelectionLength = keytext.Length; 
                        curentRch.SelectionBackColor = color;
                        isfind = curentRch.Text.IndexOf(keytext, isfind + 1);
                    }
                }
            }
        }
   
    }
}
